import QtQuick 1.1

MyPage {
    id: addContactPage


    Flickable {
        id: flickArea
        anchors.top: parent.top; anchors.topMargin: 5
        anchors.bottom: toolBar.top; anchors.bottomMargin: 5
        anchors.left: parent.left; anchors.leftMargin: 10
        anchors.right: parent.right; anchors.rightMargin: 10

        contentHeight: contentPage.height
        contentWidth: contentPage.width

        flickableDirection: Flickable.VerticalFlick

        Column {
            id: contentPage
            width: addContactPage.width - flickArea.anchors.rightMargin - flickArea.anchors.leftMargin
            spacing: 10

            Item {
                id: spacer1
                height: 30
                width: addContactPage.width
            }

            Row {
                spacing: 20
                anchors.horizontalCenter: parent.horizontalCenter
                Image {
                    id: imgAddContact
                    anchors.verticalCenter: parent.verticalCenter
                    source: "qrc:/qml/images/contact_add.png"
                }
                Text {
                    id: txtAddContact
                    anchors.verticalCenter: parent.verticalCenter
                    text: qsTr("Adding contact:")
                    font.pixelSize: 32
                }
            }

            Item {
                id: spacer11
                height: 20
                width: addContactPage.width
            }

            Text {
                id: txtJid
                anchors.horizontalCenter: parent.horizontalCenter
                text: qsTr("Jid:")
                font.pixelSize: 28
            }
            Text {
                id: txtJidExample
                anchors.horizontalCenter: parent.horizontalCenter
                text: qsTr("Example: login@server.com")
                color: "gray"
                font.pixelSize: 18
                font.italic: true
            }
            MyTextInput {
                id: tiJid
                anchors.horizontalCenter: parent.horizontalCenter
                height: 50
                width: parent.width
            }

            Item {
                id: spacer2
                height: 10
                width: addContactPage.width
            }

            Text {
                id: txtNickname
                anchors.horizontalCenter: parent.horizontalCenter
                text: qsTr("Nickname (optional):")
                font.pixelSize: 28
            }
            MyTextInput {
                id: tiNickname
                anchors.horizontalCenter: parent.horizontalCenter
                height: 50
                width: parent.width
                font.pixelSize: 28
            }

            Item {
                id: spacer3
                height: 10
                width: addContactPage.width
            }

            MyCheckBox {
                id: checkBoxAuth
                text: qsTr("Request authorization")
            }

            Item {
                height: 10
                width: addContactPage.width
            }

            Item {
                id: spacer6
                height: 5
                width: addContactPage.width
            }
        }
    }


    /******************************************/

    ToolBar {
        id: toolBar
        ToolButton {
            id: toolBarButtonRoster
            icon: "qrc:/qml/images/bar_options.png"
            anchors.left: parent.left
            anchors.leftMargin: (0.5*(parent.width/4) - 0.5*toolBarButtonRoster.width)
            onClicked: {
                addContactPage.closePage( "qrc:/qml/RosterPage.qml" )
            }
            pauseAnim: 500
        }

        ToolButton {
            id: toolBarButtonOptions
            icon: "qrc:/qml/images/bar_ok.png"
            anchors.left: parent.left
            anchors.leftMargin: (3.5*(parent.width/4) - 0.5*toolBarButtonOptions.width)
            onClicked: {
                if( tiJid.text != "" ) {
                    var sendSubcribe = false
                    if( checkBoxAuth.checked ) { sendSubcribe = true }
                    xmppClient.addContact( tiJid.text, tiNickname.text, "", sendSubcribe )
                    addContactPage.closePage( "qrc:/qml/RosterPage.qml" )
                }
            }
            pauseAnim: 600
        }
    }
}
